<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>定时任务控制</legend>
        </fieldset>

        <form class="layui-form" action="" lay-filter="example">

            <div class="layui-form-item">
                <label class="layui-form-label">类目信息同步</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="CATE_SYNC" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">商品主图处理</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="PRIMARY_PIC" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Apply申请状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="APPLY_STATE_SYNC" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Apply申请列表</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="APPLY_SYNC" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Apply审核通过商品</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="PRODUCT_INFO_SYNC" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">任务SKU导入</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="ITEM_IMPORT" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">SKU上架</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="ITEM_PUSH" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">上架SKU预处理</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="ITEM_PREHANDL" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">任务状态检测</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="TASK_CHECK" lay-skin="switch" lay-filter="switchTest" lay-text="启动|关闭">
                </div>
            </div>

        </form>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var  $ = layui.jquery
            ,form = layui.form
            , layer = layui.layer;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();


        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg(data.othis.parent().find("input").attr("name") + '：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });

            var name = data.othis.parent().find("input").attr("name");

            if ( this.checked ) {
                $.ajax({
                    type: 'GET',
                    url: "scheduled/enable?name=" + name,
                    cache: false,
                    success: function (result) {
                        console.log(result);
                    }
                });
            }  else {
                $.ajax({
                    type: 'GET',
                    url: "scheduled/disable?name=" + name,
                    cache: false,
                    success: function (result) {
                        console.log(result);
                    }
                });
            }

        });



        $.ajax({
            type: 'GET',
            url: "scheduled/status",
            cache: false,
            success: function (result) {
                form.val('example', result)
            },
            dataType: "json"
        });

        //表单初始赋值

    });
</script>